package com.mall.shopping.services;

import com.mall.shopping.IContentService;
import com.mall.shopping.converter.ContentConverter;
import com.mall.shopping.dal.entitys.PanelContent;
import com.mall.shopping.dal.persistence.PanelContentMapper;
import com.mall.shopping.dto.NavListResponse;
import com.mall.shopping.dto.PanelContentDto;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

@Service(interfaceClass = IContentService.class)
@Component
public class IContentSeriveImpl implements IContentService {

    //转换器
    @Autowired
    ContentConverter contentConverter;


    //Mapper
    @Autowired
    PanelContentMapper panelContentMapper;


    //张泽宇的查询是要查panelId = 0 的,不需要参数，如果你也用到这个方法的话要再写一个
    //如果你的也不要参数，改的时候改panelId应该就可以用
    //改之前先试试我原本的对不对，改完后试试我的能不能用
    @Override
    public NavListResponse queryNavList() {
        NavListResponse navListResponse = new NavListResponse();



        Example example = new Example(PanelContent.class);

        //排序
        example.setOrderByClause("sort_order asc");

        //添加条件panelId = 0
        //用到tk-mybatis时，里面这个属性，不能写表里的，而应该也对应bean对象的，比如这里
        //表中时panel_id，bean中时panelId，那你就要写panelId
        example.createCriteria().andEqualTo("panelId",0);
        List<PanelContent> panelContents = panelContentMapper.selectByExample(example);



        //转换成返回的Dto对象
        List<PanelContentDto> panelContentDtos = contentConverter.panelContents2Dto(panelContents);

        //封装
        navListResponse.setPannelContentDtos(panelContentDtos);


        return navListResponse;
    }
}
